

#ifdef GL_ES
precision mediump float;
#endif

uniform float u_time;
// float u_time = 1.0;
// uniform vec2 u_mouse;
uniform vec2 u_resolution;

// vec2 v = u_mouse/u_resolution;

// varying vec3 v_position;

// uniform vec3 u_color;
// float tx = (sin(u_time)+1.0 )*10.5;
// float ty = (cos(u_time)+1.0 )*0.5;

float rect(vec2 pt,vec2 size,vec2 center){
  vec2 p=pt-center;
  vec2 halfsize=size*.5;
  float horz=step(-halfsize.x,p.x)-step(halfsize.x,p.x);
  float vert=step(-halfsize.y,p.y)-step(halfsize.y,p.y);
  return horz*vert;
}

float rect2(vec2 pt,vec2 size,vec2 center){
  vec2 p=pt-center;
  vec2 halfsize=size*.5;
  float horz=step(-center.x,p.x)-step(size.x,p.x);
  float vert=step(-center.y,p.y)-step(size.y,p.y);
  return horz*vert;
}

mat2 getRotationMatrix(float theta){
  float s=sin(theta);
  float c=cos(theta);
  return mat2(c,-s,s,c);
}

void main(){
  // vec3 color = vec3( u_mouse.x/u_resolution.x, 0.0,u_mouse.y/u_resolution.y );
  // vec3 color = vec3(v.x, v.x, v.y );
  vec2 uv=gl_FragCoord.xy/u_resolution;
  vec2 v_position=uv;
  // vec3 color = vec3(tx, v.x, ty);
  //vec3 color = mix( vec3(1.0,1.0,0.0),vec3(1.0,0.0,0.0), uv.y);
  
  // float len = v_position.x*v_position.x +v_position.y*v_position.y ;
  // if(len > 0.5){ return; }
  
  vec3 color=vec3(v_position.x,v_position.y,0.);
  color.r=step(0.,v_position.x);
  color.g=smoothstep(0.,.3,v_position.y);
  color.b=clamp(-1.,v_position.x,1.);
  float inC=1.-step(.5,length(v_position.xy));
  
  vec2 center=vec2(.5)*.5;
  
  mat2 matR=getRotationMatrix(u_time);
  vec2 pt=(matR*(v_position.xy-center))+center;
  
  float rect1=rect(pt,vec2(.3),center);
  float rect2=rect(pt,vec2(.4),center);
  color=color*(rect1+rect2);
  // color = step(color, v_position.x*v_position.x +v_position.y*v_position.y );
  gl_FragColor=vec4(color,.5);
}


